import sys
import os

cur_file_path, filename = os.path.split(os.path.abspath(__file__))
sys.path.append(f"{cur_file_path}/../")

from l0n0lnet.utils import *
from l0n0lnet import *
from l0n0lnet.tcp import *
from l0n0lnet.tcp import base_client
from l0n0lnet import run



# class testclient(base_client):
#     def __init__(self, ip, port):
#         super().__init__(ip, port)

#     def on_connected(self):
#         print("连接成功")
#         self.send_msg(b'hello!')
#         self.close()

#     def on_connect_failed(self):
#         print("连接失败")

#     def on_disconnected(self):
#         print("断开连接")

#     def on_read(self, data, size):
#         print(id, data, size)


# client = testclient(b'127.0.0.1', 1234)

# run()


client_id = connect_to("test", b"192.168.1.6", 1234)


def on_connected():
    print("on_connected")

    def sssss():
        print("send")
        data = b''
        data = data.zfill(10000000)
        send_message(client_id, data)
    call_after(10, sssss, 10)


def on_connect_failed():
    print("on_connect_failed")


def on_disconnected():
    print("on_disconnected")


def on_read(data, size):
    print(data)


set_cb("test", "on_connected", on_connected)
set_cb("test", "on_connect_failed", on_connect_failed)
set_cb("test", "on_disconnected", on_disconnected)
set_cb("test", "on_read", on_read)

run()
